import { _decorator, Component, find, Label, Node } from 'cc';
const { ccclass, property } = _decorator;
import LevelManager from '../managers/LevelManager';
import goldManager from '../managers/goldManager';
import atkUp from '../managers/atkData/atkUp';
import { buyHealthBtn } from './buyHealthBtn';
import GlobalEvent from '../Global/GlobalEvent';
import healthUp from '../managers/healthData/healthUp';
import speedUp from '../managers/speedData/speedUp';
@ccclass('buyAtkBtn')
export class buyAtkBtn extends Component {
    @property(Node)
    private atkBtn: Node = null;
    @property(Node)
    private atkLv: Node = null;
    @property(Node)
    private LvScore: Node = null;
    @property(Node)
    private goldView: Node = null;


    private bool: Boolean;


    @property(Node)
    private btn_Add_Atk: Node = null;
    @property(Node)
    private btn_Add_Atk2: Node = null;

    private bgMoveLeft;

    getGold;
    getGoldBtn;

    goldatk;
    goldGetLv;

    start() {

        GlobalEvent.on('getAtkBoolean', (e) => {
            this.atkBtn.active = e;
        })
        let atkup = atkUp.getInstance();
        this.getGoldBtn = atkup.getGold();


        let goldmanager = goldManager.getInstance();
        this.getGold = goldmanager.getGold();
        if (this.goldView) {
            let label = this.goldView.getComponent(Label);
            label.string = `金币:${this.getGold}`;
        }
    }

    update(deltaTime: number) {
    }
    //购买攻击力按钮
    atkBtnFun() {
        const speedup = speedUp.getInstance();
        let goldmanager = goldManager.getInstance();
        let atkup = atkUp.getInstance();
        let healthup = healthUp.getInstance();
        var goldGetLv = atkup.getlv();
        var goldatk = atkup.getAtk();
        goldmanager.btnMinuGold(this.getGoldBtn);
        speedup.getSpeedBool();
        atkup.getAtkbool();
        healthup.getHealthbool();

        //点击购买 增加lv
        atkup.upLv();

        //获取购买攻击力的金币
        this.goldGetLv = goldGetLv;
        this.goldatk = goldatk;
        this.getGoldBtn = atkup.getGold();

        this.renderGold()

    }


    //渲染攻击力
    renderGold() {
        let goldmanager = goldManager.getInstance();
        let atkup = atkUp.getInstance();
        var goldGetLv = atkup.getlv();
        var goldatk = atkup.getAtk();

        this.getGold = goldmanager.getGold();
        this.getGoldBtn = atkup.getGold();

        //获取购买攻击力的金币
        this.goldGetLv = goldGetLv;
        this.goldatk = goldatk;

        let goldview = this.goldView.getComponent(Label)
        goldview.string = `金币:${this.getGold}`

        let atkLv = this.atkLv.getComponent(Label)
        atkLv.string = `Lv.${this.goldGetLv}`

        let LvScore = this.LvScore.getComponent(Label)
        LvScore.string = `+${this.goldatk}`

        let btn_Add_Atk = this.btn_Add_Atk.getComponent(Label)
        btn_Add_Atk.string = `${this.getGoldBtn}`

        let btn_Add_Atk2 = this.btn_Add_Atk2.getComponent(Label)
        btn_Add_Atk2.string = `${this.getGoldBtn}`




    }
}

